package com.lcm.learn.shardingjdbctest.config;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;


import java.util.Collection;

/**
 * @description: 自定义表分片规则
 * @author: lcm
 * @create: 2020-04-01 09:14
 **/

public class TablePreciseShardingAlgorithm implements PreciseShardingAlgorithm<Integer> {

    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<Integer> preciseShardingValue) {
        return preciseShardingValue.getLogicTableName()+"_"+((preciseShardingValue.getValue() / 2) % 2);
    }

}
